package com.fr.chart.core.glyph;

import com.fr.base.background.GradientBackground;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.SeriesAttrBackground;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.math.Plot3D;
import com.fr.chart.math.Projection;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.SeriesAttr;
import com.fr.chart.plot.SeriesCollection;
import com.fr.chart.shape3d.Cubic;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;

public class Bar3DPlotGlyph extends BarPlotGlyph
  implements Plot3D
{
  private static final long serialVersionUID = -8494817723580336519L;
  public static final String XML_TAG = "Bar3DPlotGlyph";
  private boolean isCubic3D = true;
  private boolean isCascade = true;
  private double seriesIntervalPercent = 0.0D;
  private int deep = -1;
  private boolean horizontalDrawBar = false;
  private Projection projection = new Projection();

  public void layoutAxisGlyph()
  {
    super.layoutAxisGlyph();
    layout3DAxisGlyph();
  }

  public void layoutDataSeriesGlyph()
  {
    if (this.deep == -1)
      this.deep = (int)getBounds().getWidth();
    for (int i = 0; i < getSeriesSize(); ++i)
    {
      DataSeries localDataSeries = getSeries(i);
      for (int j = 0; j < localDataSeries.getDataPointCount(); ++j)
      {
        DataPoint localDataPoint = localDataSeries.getDataPoint(j);
        if (localDataPoint.isValueIsNull())
          break label313:
        Cubic localCubic = new Cubic();
        localCubic.setProjection(getProjection());
        localCubic.getInfo().dealCondition(getSeriesCollection(), i);
        localDataPoint.setDrawImpl(localCubic);
        if (getSeriesCollection().getSeriesAttr(i).isContains(new SeriesAttrBackground()) == null)
        {
          localObject = com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY[(i % com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY.length)];
          localCubic.getInfo().setBackground(new GradientBackground(((Color)localObject).brighter(), (Color)localObject, GradientBackground.LEFT2RIGHT));
        }
        Object localObject = getBarShape(i, j);
        double d1 = 0.0D;
        double d2 = 0.0D;
        if ((isCascade()) && (!(isStacked())))
        {
          d1 = this.deep / (1.0D + getSeriesIntervalPercent()) * getSeriesSize();
          d2 = -getSeriesIntervalPercent() * d1 * (0.5D + i) - d1 * i;
        }
        else
        {
          d1 = this.deep / (1.0D + getSeriesIntervalPercent());
          d2 = -getSeriesIntervalPercent() * d1 * 0.5D;
        }
        if (this.horizontalDrawBar)
        {
          d2 = 0.0D;
          d1 = 100.0D;
        }
        localCubic.setCubic(((Rectangle2D)localObject).getX(), ((Rectangle2D)localObject).getY(), d2, ((Rectangle2D)localObject).getWidth(), ((Rectangle2D)localObject).getHeight(), d1);
        dealDataPointLabelBounds(localDataPoint, i);
      }
    }
    label313:
  }

  protected void dealDataPointLabelBounds(DataPoint paramDataPoint, int paramInt)
  {
    TextGlyph localTextGlyph = paramDataPoint.getDataLabel();
    if (localTextGlyph == null)
      return;
    Dimension2D localDimension2D = localTextGlyph.preferredDimension();
    Rectangle2D localRectangle2D = paramDataPoint.getShape().getBounds2D();
    if (this.isHorizontal)
      localTextGlyph.setBounds(new Rectangle2D.Double(localRectangle2D.getX() + localRectangle2D.getWidth(), localRectangle2D.getY() + (localRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth(), localDimension2D.getHeight()));
    else
      localTextGlyph.setBounds(new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() - localDimension2D.getHeight(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight()));
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if (this.valueAxisGlyph != null)
      this.valueAxisGlyph.draw(paramGraphics);
    if (this.categoryAxisGlyph != null)
      this.categoryAxisGlyph.draw(paramGraphics);
    if ((this.isCascade) && (!(this.isStacked)))
    {
      if (this.horizontalDrawBar)
      {
        i = 0;
        while (true)
        {
          if (i >= getSeries(0).getDataPointCount())
            break label152;
          for (int j = 0; j < getSeriesSize(); ++j)
            getSeries(j).getDataPoint(i).draw(localGraphics2D);
          ++i;
        }
      }
      for (i = getSeriesSize() - 1; i >= 0; --i)
        getSeries(i).draw(paramGraphics);
      label152: i = getSeriesSize() - 1;
      while (true)
      {
        if (i < 0)
          break label387;
        getSeries(i).drawLabel(paramGraphics);
        --i;
      }
    }
    for (int i = 0; i < getSeries(0).getDataPointCount(); ++i)
    {
      DataPoint[] arrayOfDataPoint = new DataPoint[getSeriesSize()];
      for (int l = 0; l < getSeriesSize(); ++l)
        arrayOfDataPoint[l] = getSeries(l).getDataPoint(i);
      for (l = 0; l < getSeriesSize(); ++l)
        for (int i1 = getSeriesSize() - 1; i1 > l; --i1)
          if ((!(arrayOfDataPoint[i1].isValueIsNull())) && (arrayOfDataPoint[i1].getValue() < 0.0D))
          {
            DataPoint localDataPoint = arrayOfDataPoint[i1];
            arrayOfDataPoint[i1] = arrayOfDataPoint[(i1 - 1)];
            arrayOfDataPoint[(i1 - 1)] = localDataPoint;
          }
      for (l = 0; l < getSeriesSize(); ++l)
        arrayOfDataPoint[l].draw(paramGraphics);
    }
    i = 0;
    int k = getSeriesSize();
    while (i < k)
    {
      getSeries(i).drawLabel(paramGraphics);
      ++i;
    }
    label387: localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
  }

  public void setCubic3D(boolean paramBoolean)
  {
    this.isCubic3D = paramBoolean;
  }

  public boolean isCubic3D()
  {
    return this.isCubic3D;
  }

  public void setCascade(boolean paramBoolean)
  {
    this.isCascade = paramBoolean;
  }

  public boolean isCascade()
  {
    return this.isCascade;
  }

  public void setSeriesIntervalPercent(double paramDouble)
  {
    this.seriesIntervalPercent = paramDouble;
  }

  public double getSeriesIntervalPercent()
  {
    return this.seriesIntervalPercent;
  }

  public void setDeep(int paramInt)
  {
    this.deep = paramInt;
  }

  public int getDeep()
  {
    return this.deep;
  }

  public void setHorizontalDrawBar(boolean paramBoolean)
  {
    this.horizontalDrawBar = paramBoolean;
  }

  public boolean isHorizontalDrawBar()
  {
    return this.horizontalDrawBar;
  }

  public Projection getProjection()
  {
    return this.projection;
  }

  public void setProjection(Projection paramProjection)
  {
    this.projection = paramProjection;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Bar3DPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("deep", this.deep).attr("isCas", this.isCascade).attr("isCubic", this.isCubic3D).attr("seriesPercent", this.seriesIntervalPercent).attr("horizontalDrawBar", this.horizontalDrawBar).end();
    if (this.projection != null)
      this.projection.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("deep")) != null)
          this.deep = Integer.valueOf(str2).intValue();
        if ((str2 = paramXMLableReader.getAttr("isCas")) != null)
          this.isCascade = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isCubic")) != null)
          this.isCubic3D = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("seriesPercent")) != null)
          this.seriesIntervalPercent = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("horizontalDrawBar")) != null)
          this.horizontalDrawBar = Boolean.valueOf(str2).booleanValue();
      }
      else if (str1.equals("Projection"))
      {
        this.projection = ((Projection)paramXMLableReader.readXMLObject(new Projection()));
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Bar3DPlotGlyph))
      return false;
    Bar3DPlotGlyph localBar3DPlotGlyph = (Bar3DPlotGlyph)paramObject;
    if (!(super.equals(localBar3DPlotGlyph)))
      return false;
    if (localBar3DPlotGlyph.deep != this.deep)
      return false;
    if (localBar3DPlotGlyph.isCascade != this.isCascade)
      return false;
    if (localBar3DPlotGlyph.horizontalDrawBar != this.horizontalDrawBar)
      return false;
    if (localBar3DPlotGlyph.isCubic3D != this.isCubic3D)
      return false;
    if (localBar3DPlotGlyph.seriesIntervalPercent != this.seriesIntervalPercent)
      return false;
    return (Equals.equals(localBar3DPlotGlyph.projection, this.projection));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Bar3DPlotGlyph localBar3DPlotGlyph = (Bar3DPlotGlyph)super.clone();
    if (this.projection != null)
      localBar3DPlotGlyph.projection = ((Projection)this.projection.clone());
    return localBar3DPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("deep", this.deep);
    localJSONObject.put("isCascade", this.isCascade);
    localJSONObject.put("isCubic3D", this.isCubic3D);
    localJSONObject.put("seriesIntervalPercent", this.seriesIntervalPercent);
    localJSONObject.put("horizontalDrawBar", this.horizontalDrawBar);
    if (this.projection != null)
      localJSONObject.put("projection", this.projection.toJSONObject());
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "Bar3DPlotGlyph";
  }
}